/*
package com.example.springboot_zc.controller;

import com.example.springboot_zc.Utils.QiniuUtils;
import com.example.springboot_zc.Utils.Result;
import com.example.springboot_zc.service.userService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

@RestController
@RequestMapping("upload")
public class UploadController {
    @Autowired
    private QiniuUtils qiniuUtils;

    @Autowired
    userService userService;

    @PostMapping
    public Result upload(@RequestParam("image") MultipartFile file){
        //原始文件名
        String originalFilename = file.getOriginalFilename();
        //生成随机且唯一的文件名
//      String fileName = UUID.randomUUID().toString() + "." + StringUtils.substringAfterLast(originalFilename, ".");
        //根据用户名和文件名生成最终文件名
        String userName = "201543344";
        String fileName = "sss";
        String filename = userName+fileName+"."+StringUtils.substringAfterLast(originalFilename,".");
        boolean upload = qiniuUtils.upload(file, filename);
        if (upload){
            //将文件名传入数据库
            Result res = userService.UpdateFileName(filename, userName);
            System.out.println(res);
            return Result.success(QiniuUtils.url + filename + userName);
        }
        return Result.fail(20001,"上传失败");
    }


}
*/
